#include "ADUGameManager.h"

GameManager *GameManager::instance = NULL;

GameManager* GameManager::getInstance() {
	if(instance == NULL) {
		instance = new GameManager();
	}
	return instance;
}


void GameManager::RunScene(int scene) {
	Scene *pScene = NULL;

	if (scene == MAIN_SCENE) {
		pScene = MainLayer::createScene();
	} else if (scene == GAMEOVER_SCENE) {
	    pScene = GameOverLayer::createScene();
	} else if (scene == SPLASH_SCENE) {
		pScene = SplashLayer::createScene();
	}

	if (Director::getInstance()->getRunningScene() == NULL) {
		Director::getInstance()->runWithScene(pScene);
	} else {
		//Scene* newScene = TransitionCrossFade::create(0.5, pScene);
		if(pScene)
		{
			Director::getInstance()->replaceScene(pScene);
		}
	}
}


void GameManager::saveBestScore() {
    if(true == checkBestScore()) {
        UserDefault *def = UserDefault::getInstance();
        def->setIntegerForKey(BEST_SCORE_KEY,_score);
        def->flush();
    }  
}
bool GameManager::checkBestScore() {
    int best = UserDefault::getInstance()->getIntegerForKey(BEST_SCORE_KEY,0);
    return _score >= best ? true : false;
}

